package com.a3dweijing.wetouch2.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.bean.PartitionMsg;
import com.a3dweijing.wetouch2.callback.PartitionOnclick;


/**
 * Created by yxd on 2017/11/5.
 */

public class PartitionAdapter extends RecyclerView.Adapter<PartitionAdapter.MyViewHolder> {
    Context context;
    PartitionMsg partitionMsg;
    PartitionOnclick onclick;

    public PartitionAdapter(Context context, PartitionMsg partitionMsg) {
        this.context = context;
        this.partitionMsg = partitionMsg;
    }

    public void setOnclick(PartitionOnclick onclick) {
        this.onclick = onclick;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_partition,parent,false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        switch (position){
            case 0:
                holder.recyclerView.setLayoutManager(new GridLayoutManager(context,4));
                holder.recyclerView.setAdapter(new PartitionTopRecAdapter(context,partitionMsg.getVideoTypeList(),onclick));
                break;
            case 1:
                holder.recyclerView.setLayoutManager(new LinearLayoutManager(context));
                holder.recyclerView.setAdapter(new PartitionRecommendRecAdapter(partitionMsg.getRecommendList(),context,onclick));
                break;
        }

    }

    @Override
    public int getItemCount() {
        return 2;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        RecyclerView recyclerView;
        public MyViewHolder(View itemView) {
            super(itemView);
            recyclerView= (RecyclerView) itemView.findViewById(R.id.partition_rec);
        }
    }
}
